﻿////////////////////////////////////////////////////////////////////////
//Autor: Gabriel Tame Borao  - gabrieltame@yahoo.es 
//Fecha: 2010/09/15 01:26
//Solucion: GTameReport.sln
//Proyecto: GTameReport
//Fichero: Report.cs
//
//	Copyright (C) 2010  Gabriel Tame Borao (GTB)
//
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
namespace GTameReport
{
    using Rdl;
    using System;
    using System.Collections;
    using System.IO;
    using System.Xml.Serialization;

    public class Report
    {
        private string _Author;
        private uint? _AutoRefresh = null;
        private GTameReport.BodyType _Body;
        private string _BottomMargin;
        private GTameReport.ClassesType _Classes;
        private string _Code;
        private GTameReport.CodeModulesType _CodeModules;
        private GTameReport.CustomPropertiesType _CustomProperties;
        private string _DataElementName;
        private ReportDataElementStyle _DataElementStyle = ReportDataElementStyle.ElementNormal;
        private string _DataSchema;
        private GTameReport.DataSetsType _DataSets;
        private GTameReport.DataSourcesType _DataSources;
        private string _DataTransform;
        private string _Description;
        private GTameReport.EmbeddedImagesType _EmbeddedImages;
        private string _InteractiveHeight;
        private string _InteractiveWidth;
        private string _Language;
        private string _LeftMargin;
        private GTameReport.PageHeaderFooterType _PageFooter;
        private GTameReport.PageHeaderFooterType _PageHeader;
        private string _PageHeight;
        private string _PageWidth;
        private GTameReport.ReportParametersType _ReportParameters;
        private string _RightMargin;
        private string _TopMargin;
        private string _Width;



        public void Write(string path)
        {

            System.IO.FileStream file = new System.IO.FileStream(path, System.IO.FileMode.Create);
            byte[] bytes = GetStream().GetBuffer();
            int _count = (int)Math.Ceiling((decimal)((decimal)bytes.LongLength / 1024));

            for (int i = 0; i < _count; i++)
            {
                file.Write(bytes, i*1024, (int)(bytes.LongLength>((i+1)*1024)?1024:(bytes.LongLength-(i*1024))));
            }
            
            file.Flush();
            file.Close();
            file = null;
        }

        public MemoryStream GetStream()
        {
            MemoryStream stream = new MemoryStream();
            new XmlSerializer(typeof(Rdl.Report)).Serialize((Stream) stream, this.Write());
            stream.Position = 0L;
            return stream;
        }

        public Rdl.Report Write()
        {
            Rdl.Report report = new Rdl.Report();
            ArrayList list = new ArrayList();
            ArrayList list2 = new ArrayList();
            if (this._Author != null)
            {
                list.Add(this._Author);
                list2.Add(ItemsChoiceType37.Author);
            }
            if (this._AutoRefresh.HasValue)
            {
                list.Add(this._AutoRefresh);
                list2.Add(ItemsChoiceType37.AutoRefresh);
            }
            if (this._Body != null)
            {
                list.Add(this._Body.Write());
                list2.Add(ItemsChoiceType37.Body);
            }
            if (this._BottomMargin != null)
            {
                list.Add(this._BottomMargin);
                list2.Add(ItemsChoiceType37.BottomMargin);
            }
            if (this._Classes != null)
            {
                list.Add(this._Classes.Write());
                list2.Add(ItemsChoiceType37.Classes);
            }
            if (this._Code != null)
            {
                list.Add(this._Code);
                list2.Add(ItemsChoiceType37.Code);
            }
            if (this._CodeModules != null)
            {
                list.Add(this._CodeModules.Write());
                list2.Add(ItemsChoiceType37.CodeModules);
            }
            if (this._CustomProperties != null)
            {
                list.Add(this._CustomProperties.Write());
                list2.Add(ItemsChoiceType37.CustomProperties);
            }
            if (this._DataElementName != null)
            {
                list.Add(this._DataElementName);
                list2.Add(ItemsChoiceType37.DataElementName);
            }
            list.Add(this._DataElementStyle);
            list2.Add(ItemsChoiceType37.DataElementStyle);
            if (this._DataSchema != null)
            {
                list.Add(this._DataSchema);
                list2.Add(ItemsChoiceType37.DataSchema);
            }
            if (this._DataSets != null)
            {
                list.Add(this._DataSets.Write());
                list2.Add(ItemsChoiceType37.DataSets);
            }
            if (this._DataSources != null)
            {
                list.Add(this._DataSources.Write());
                list2.Add(ItemsChoiceType37.DataSources);
            }
            if (this._DataTransform != null)
            {
                list.Add(this._DataTransform);
                list2.Add(ItemsChoiceType37.DataTransform);
            }
            if (this._Description != null)
            {
                list.Add(this._Description);
                list2.Add(ItemsChoiceType37.Description);
            }
            if (this._EmbeddedImages != null)
            {
                list.Add(this._EmbeddedImages.Write());
                list2.Add(ItemsChoiceType37.EmbeddedImages);
            }
            if (this._InteractiveHeight != null)
            {
                list.Add(this._InteractiveHeight);
                list2.Add(ItemsChoiceType37.InteractiveHeight);
            }
            if (this._InteractiveWidth != null)
            {
                list.Add(this._InteractiveWidth);
                list2.Add(ItemsChoiceType37.InteractiveWidth);
            }
            if (this._Language != null)
            {
                list.Add(this._Language);
                list2.Add(ItemsChoiceType37.Language);
            }
            if (this._LeftMargin != null)
            {
                list.Add(this._LeftMargin);
                list2.Add(ItemsChoiceType37.LeftMargin);
            }
            if (this._PageFooter != null)
            {
                list.Add(this._PageFooter.Write());
                list2.Add(ItemsChoiceType37.PageFooter);
            }
            if (this._PageHeader != null)
            {
                list.Add(this._PageHeader.Write());
                list2.Add(ItemsChoiceType37.PageHeader);
            }
            if (this._PageHeight != null)
            {
                list.Add(this._PageHeight);
                list2.Add(ItemsChoiceType37.PageHeight);
            }
            if (this._PageWidth != null)
            {
                list.Add(this._PageWidth);
                list2.Add(ItemsChoiceType37.PageWidth);
            }
            if (this._ReportParameters != null)
            {
                list.Add(this._ReportParameters.Write());
                list2.Add(ItemsChoiceType37.ReportParameters);
            }
            if (this._RightMargin != null)
            {
                list.Add(this._RightMargin);
                list2.Add(ItemsChoiceType37.RightMargin);
            }
            if (this._TopMargin != null)
            {
                list.Add(this._TopMargin);
                list2.Add(ItemsChoiceType37.TopMargin);
            }
            if (this._Width != null)
            {
                list.Add(this._Width);
                list2.Add(ItemsChoiceType37.Width);
            }
            report.Items = list.ToArray();
            report.ItemsElementName = (ItemsChoiceType37[]) list2.ToArray(typeof(ItemsChoiceType37));
            list2 = null;
            list = null;
            return report;
        }

        public string Author
        {
            get
            {
                return this._Author;
            }
            set
            {
                this._Author = value;
            }
        }

        public uint? AutoRefresh
        {
            get
            {
                return this._AutoRefresh;
            }
            set
            {
                this._AutoRefresh = value;
            }
        }

        public GTameReport.BodyType Body
        {
            get
            {
                if (this._Body == null)
                {
                    this._Body = new GTameReport.BodyType();
                }
                return this._Body;
            }
            set
            {
                this._Body = value;
            }
        }

        public string BottomMargin
        {
            get
            {
                return this._BottomMargin;
            }
            set
            {
                this._BottomMargin = value;
            }
        }

        public GTameReport.ClassesType Classes
        {
            get
            {
                if (this._Classes == null)
                {
                    this._Classes = new GTameReport.ClassesType();
                }
                return this._Classes;
            }
            set
            {
                this._Classes = value;
            }
        }

        public string Code
        {
            get
            {
                return this._Code;
            }
            set
            {
                this._Code = value;
            }
        }

        public GTameReport.CodeModulesType CodeModules
        {
            get
            {
                if (this._CodeModules == null)
                {
                    this._CodeModules = new GTameReport.CodeModulesType();
                }
                return this._CodeModules;
            }
            set
            {
                this._CodeModules = value;
            }
        }

        public GTameReport.CustomPropertiesType CustomProperties
        {
            get
            {
                if (this._CustomProperties == null)
                {
                    this._CustomProperties = new GTameReport.CustomPropertiesType();
                }
                return this._CustomProperties;
            }
            set
            {
                this._CustomProperties = value;
            }
        }

        public string DataElementName
        {
            get
            {
                return this._DataElementName;
            }
            set
            {
                this._DataElementName = value;
            }
        }

        public ReportDataElementStyle DataElementStyle
        {
            get
            {
                return this._DataElementStyle;
            }
            set
            {
                this._DataElementStyle = value;
            }
        }

        public string DataSchema
        {
            get
            {
                return this._DataSchema;
            }
            set
            {
                this._DataSchema = value;
            }
        }

        public GTameReport.DataSetsType DataSets
        {
            get
            {
                if (this._DataSets == null)
                {
                    this._DataSets = new GTameReport.DataSetsType();
                }
                return this._DataSets;
            }
            set
            {
                this._DataSets = value;
            }
        }

        public GTameReport.DataSourcesType DataSources
        {
            get
            {
                if (this._DataSources == null)
                {
                    this._DataSources = new GTameReport.DataSourcesType();
                }
                return this._DataSources;
            }
            set
            {
                this._DataSources = value;
            }
        }

        public string DataTransform
        {
            get
            {
                return this._DataTransform;
            }
            set
            {
                this._DataTransform = value;
            }
        }

        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                this._Description = value;
            }
        }

        public GTameReport.EmbeddedImagesType EmbeddedImages
        {
            get
            {
                if (this._EmbeddedImages == null)
                {
                    this._EmbeddedImages = new GTameReport.EmbeddedImagesType();
                }
                return this._EmbeddedImages;
            }
            set
            {
                this._EmbeddedImages = value;
            }
        }

        public string InteractiveHeight
        {
            get
            {
                return this._InteractiveHeight;
            }
            set
            {
                this._InteractiveHeight = value;
            }
        }

        public string InteractiveWidth
        {
            get
            {
                return this._InteractiveWidth;
            }
            set
            {
                this._InteractiveWidth = value;
            }
        }

        public string Language
        {
            get
            {
                return this._Language;
            }
            set
            {
                this._Language = value;
            }
        }

        public string LeftMargin
        {
            get
            {
                return this._LeftMargin;
            }
            set
            {
                this._LeftMargin = value;
            }
        }

        public GTameReport.PageHeaderFooterType PageFooter
        {
            get
            {
                if (this._PageFooter == null)
                {
                    this._PageFooter = new GTameReport.PageHeaderFooterType();
                }
                return this._PageFooter;
            }
            set
            {
                this._PageFooter = value;
            }
        }

        public GTameReport.PageHeaderFooterType PageHeader
        {
            get
            {
                if (this._PageHeader == null)
                {
                    this._PageHeader = new GTameReport.PageHeaderFooterType();
                }
                return this._PageHeader;
            }
            set
            {
                this._PageHeader = value;
            }
        }

        public string PageHeight
        {
            get
            {
                return this._PageHeight;
            }
            set
            {
                this._PageHeight = value;
            }
        }

        public string PageWidth
        {
            get
            {
                return this._PageWidth;
            }
            set
            {
                this._PageWidth = value;
            }
        }

        public GTameReport.ReportParametersType ReportParameters
        {
            get
            {
                if (this._ReportParameters == null)
                {
                    this._ReportParameters = new GTameReport.ReportParametersType();
                }
                return this._ReportParameters;
            }
            set
            {
                this._ReportParameters = value;
            }
        }

        public string RightMargin
        {
            get
            {
                return this._RightMargin;
            }
            set
            {
                this._RightMargin = value;
            }
        }

        public string TopMargin
        {
            get
            {
                return this._TopMargin;
            }
            set
            {
                this._TopMargin = value;
            }
        }

        public string Width
        {
            get
            {
                return this._Width;
            }
            set
            {
                this._Width = value;
            }
        }
    }
}

